/**
 * Created by zycool on 2016/9/6.
 * 管理仪表板 - 腐蚀控制
 */


;(function ($, window, document, undefined) {

    /*** 阴极保护 - start ***/
    // 管道
    var $pipeline = $('#JQ_pipeline').select3();
    // 管段
    var $segment = $('#JQ_segment').select3({
        title: '管段'
    });
    // 起点位置
    var $begin = $('#JQ_begin').select3({
        title: '起点位置',
        server: true,
        param: {
            'pipeLineId': $pipeline,
            'pipeSegmentId': $segment
        }
    });
    // 终点位置
    var $end = $('#JQ_end').select3({
        title: '终点位置',
        server: true,
        param: {
            'pipeLineId': $pipeline,
            'pipeSegmentId': $segment,
            'beginSignId': $begin
        }
    });
    // 触发管道
    $pipeline.element.on('select', function (e, v) {
        var id = v || $pipeline.val();
        if (id) {
            // 管段
            DyyBase.ajax(DyyBase.url_segment(), {pipeLineId: id}, function (dataset) {
                var json = DyyBase.getSelect(dataset);
                $segment.add(json);
            });
            // 起点 & 终点
            DyyBase.ajax(DyyBase.url_pipe_pos(), {pipeLineId: id}, function (dataset) {
                var begin = DyyBase.getPos(dataset, 'begin', true);
                var end = DyyBase.getPos(dataset, 'end', true);
                $begin.asset(begin);
                $end.asset(end);
            });
        } else {
            $segment.add([]);
            $begin.add([]);
            $end.add([]);
        }
    });
    // 触发管段
    $segment.element.on('select', function (e, v) {
        var id = v || $segment.val();
        if (id) {
            // 起点 & 终点
            DyyBase.ajax(DyyBase.url_segment_pos(), {pipeSegmentId: id}, function (dataset) {
                var begin = DyyBase.getPos(dataset, 'begin', true);
                var end = DyyBase.getPos(dataset, 'end', true);
                $begin.asset(begin);
                $end.asset(end);
            });
        } else {
            $begin.add([]);
            $end.add([]);
        }
    });

    // 默认选中
    $pipeline.element.trigger('select');

    var filter_rate = {
        getSearch: function () {
            var data = {};
            data.mode = true;
            data.pipeLineId = function () {
                var v = $pipeline.val();
                if (v) {
                    return v;
                } else {
                    $pipeline.element.TIP({content: '管道名称不能为空!'});
                    data.mode = false;
                }
                return '';
            }();
            data.pipeLineName = function () {
                var v = $pipeline.val('text');
                if (v) {
                    return v;
                }
                return '';
            }();
            data.beginMileage = function () {
                var v = $begin.val('mile');
                if (DyyBase.notEmpty(v)) {
                    return v;
                }
                return '';
            }();
            data.endMileage = function () {
                var v = $end.val('mile');
                if (DyyBase.notEmpty(v)) {
                    return v;
                }
                return '';
            }();
            return data;
        }
    };

    // 显示保护率&运行率
    function showLed(b, n, t) {
        var $lv_lgreen = $('#JQ_lv_lgreen');
        var $lv_lblue = $('#JQ_lv_lblue');

        if (b) {
            $lv_lgreen.parent('div.zy-charts-body').find('img.empty').remove();
            $lv_lblue.parent('div.zy-charts-body').find('img.empty').remove();
            $lv_lgreen.fadeIn('fast');
            $lv_lblue.fadeIn('fast');

            var hun = '', ten = '', bit = '', dec = '';
            var strnum = (n.toString()).split('.');
            //console.log(strnum);
            if (strnum[0].length === 3) {
                hun = strnum[0].substr(0, 1);
                ten = strnum[0].substr(1, 1);
                bit = strnum[0].substr(2, 1);
            } else if (strnum[0].length === 2) {
                ten = strnum[0].substr(0, 1);
                bit = strnum[0].substr(1, 1);
            } else if (strnum[0].length === 1) {
                bit = strnum[0].substr(0, 1);
            }
            if (strnum[1].length === 1) {
                dec = strnum[1].substr(0, 1);
            }

            var h_css = 'zy-lv-', l_css = 'zy-lv-', m_css = 'zy-lv-', r_css = 'zy-lv-';
            if (t == 'green') {
                h_css += 'green-' + hun + ' zy-lspan';
                l_css += 'green-' + ten + ' zy-lspan';
                m_css += 'green-' + bit + ' zy-lspan';
                r_css += 'green-' + dec + ' zy-lspan';
                $('#JQ_lv_green_hun').removeClass().addClass(h_css);
                $('#JQ_lv_green_ten').removeClass().addClass(l_css);
                $('#JQ_lv_green_bit').removeClass().addClass(m_css);
                $('#JQ_lv_green_dec').removeClass().addClass(r_css);
            } else if (t == 'blue') {
                h_css += 'blue-' + hun + ' zy-lspan';
                l_css += 'blue-' + ten + ' zy-lspan';
                m_css += 'blue-' + bit + ' zy-lspan';
                r_css += 'blue-' + dec + ' zy-lspan';
                $('#JQ_lv_blue_hun').removeClass().addClass(h_css);
                $('#JQ_lv_blue_ten').removeClass().addClass(l_css);
                $('#JQ_lv_blue_bit').removeClass().addClass(m_css);
                $('#JQ_lv_blue_dec').removeClass().addClass(r_css);
            }
        } else {
            $lv_lgreen.hide('fast');
            $lv_lblue.hide('fast');

            var empty = $lv_lgreen.parent('div.zy-charts-body').attr('data-loss');
            if (empty) {
                $lv_lgreen.parent('div.zy-charts-body').append('<img class="empty" src="' + empty + '">');
                $lv_lblue.parent('div.zy-charts-body').append('<img class="empty" src="' + empty + '">');
            }
        }
    }

    // 默认显示
    showLed();

    // 查询
    $('#JQ_search_rate').click(function () {
        var param = filter_rate.getSearch();
        if (param.mode) {
            $('#JQ_export_rate').attr('data-empty','false');
            DyyBase.ajax(corrctrlApi.url_dash_rate(), param, function (dataset) {

                if (dataset.bool) {
                    // 运行率
                    var pro_lv = DyyBase.clearNaN(dataset.result.cpTestStationOperatingRatioMap.AVG_OPERATINGRATIO);
                    showLed(true, (pro_lv * 100).toFixed(1), 'blue');
                    // 保护率
                    var all = DyyBase.clearNaN(dataset.result.cpTestStationProtectionRatioMap.ALL_COUNT);
                    var q = DyyBase.clearNaN(dataset.result.cpTestStationProtectionRatioMap.COUNT_Q);
                    if (all !== 0) {
                        var lv = (all - q) / all * 100;
                        showLed(true, lv.toFixed(1), 'green');
                    } else {
                        showLed(true, (0).toFixed(1), 'green');
                    }
                    // 折线图
                    var data = [
                        [
                            {x: 'A1', y: 1.0},
                            {x: 'A2', y: 2.2},
                            {x: 'A3', y: 1.8},
                            {x: 'A4', y: 2.8},
                            {x: 'A5', y: 1.5},
                            {x: 'A6', y: 3.8},
                            {x: 'A7', y: 2.2},
                            {x: 'A8', y: 1.8},
                            {x: 'A9', y: 2.6},
                            {x: 'A10', y: 3.0}
                        ],
                        [
                            {x: 'A1', y: 4},
                            {x: 'A2', y: 4.6},
                            {x: 'A3', y: 4.1},
                            {x: 'A4', y: 5},
                            {x: 'A5', y: 4.7},
                            {x: 'A6', y: 5.4},
                            {x: 'A7', y: 4.8},
                            {x: 'A8', y: 6},
                            {x: 'A9', y: 5.8},
                            {x: 'A10', y: 7}
                        ],
                        [
                            {x: 'A1', y: 8},
                            {x: 'A2', y: 8.8},
                            {x: 'A3', y: 8.3},
                            {x: 'A4', y: 8.9},
                            {x: 'A5', y: 9.4},
                            {x: 'A6', y: 12},
                            {x: 'A7', y: 9.2},
                            {x: 'A8', y: 13},
                            {x: 'A9', y: 12},
                            {x: 'A10', y: 13.8}
                        ]
                    ];

                    // ON_POTENTIAL通电电位
                    var ON_POTENTIAL = d3Charts.formart(dataset.result.cpTestStationRecodeList, {
                        x: 'CUSTOM_NUMBER',
                        y: 'ON_POTENTIAL'
                    });

                    // OFF_POTENTIAL断电电位
                    var OFF_POTENTIAL = d3Charts.formart(dataset.result.cpTestStationRecodeList, {
                        x: 'CUSTOM_NUMBER',
                        y: 'OFF_POTENTIAL'
                    });

                    // FREE_CORROSION_POTENTIAL自然电位
                    var FREE_CORROSION_POTENTIAL = d3Charts.formart(dataset.result.cpTestStationRecodeList, {
                        x: 'CUSTOM_NUMBER',
                        y: 'FREE_CORROSION_POTENTIAL'
                    });

                    // 所有数据
                    var alldata = [ON_POTENTIAL, OFF_POTENTIAL, FREE_CORROSION_POTENTIAL];
                    if (alldata[0].length > 0 || alldata[1].length > 0 || alldata[2].length > 0) {
                        d3Charts.ordinal({
                            container: 'JQ_cathodic_electric',
                            color: ['#2abf63', '#f36e4b', '#409ee8'],
                            data: alldata,
                            tip: {
                                show: true,
                                xtag: '测试桩：',
                                ytag: ['通电电位：', '断电/极化电位：', '自然电位：']
                            },
                            xAxis: {
                                ticks: Infinity
                            },
                            yAxis: {
                                ticks: Infinity,
                                render: function(d){
                                    return parseInt(d);
                                }
                            },
                            layout: {
                                xtag: '测试桩',
                                ytag: '电位值(mV)',
                                margin: {
                                    left: 50,
                                    right: 30,
                                    top: 30,
                                    bottom: 40
                                },
                                ygrid: true
                            }
                        });
                    }else{
                        $('#JQ_cathodic_electric').trigger('clear');
                    }
                }
            });
        }else{
            $('#JQ_export_rate').attr('data-empty','true');
        }
    });

    // 设置那左右两个div宽度
    function setWidth() {
        var $out = $('#JQ_out_box');
        var w = $out.width();
        var $right = $('#JQ_right_box');
        $right.width(w - 330 - 25);
        DyyBase.setChartWidth();
    }

    /* 临时方法 */
    setWidth();

    window.onresize = function () {
        setWidth();
    };

    // 导出pdf
    $('#JQ_export_rate').click(function(){
        var $this = $(this);
        DyyBase.isLogin(function(){
            var empty = $this.attr('data-empty');
            if(empty == 'true'){
                $this.MSG({
                    content: '尚未进行查询,将不能进行pdf导出!'
                });
            }else{
                var param = filter_rate.getSearch();
                if(param.pipeLineName){
                    $this.EXPT({
                        type: 'name',
                        name: param.pipeLineName + '阴极保护统计图',
                        yesBtnAct: function (callback, fname) {
                            callback();
                            canvasPdf.exportHtmlPdf({
                                dom: $('#JQ_out_box'),
                                server: DyyBase.root_path + '/comm/downImgPdf.json',
                                param: {
                                    fileName: fname,
                                    name: fname
                                }
                            });
                        }
                    });
                }
            }
        });
    });
    /*** 阴极保护 - end ***/


    /*** 交直流干扰 - start ***/
    // 管道
    var $pipeline_disturb = $('#JQ_pipeline_disturb').select3({
        data: $pipeline.val('store'),
        title: '管道'
    });
    // 管段
    var $segment_disturb = $('#JQ_segment_disturb').select3({
        title: '管段'
    });
    // 起点位置
    var $begin_disturb = $('#JQ_begin_disturb').select3({
        title: '起点位置',
        server: true,
        param: {'pipeLineId': $pipeline_disturb, 'pipeSegmentId': $segment_disturb}
    });
    // 终点位置
    var $end_disturb = $('#JQ_end_disturb').select3({
        title: '终点位置',
        server: true,
        param: {'pipeLineId': $pipeline_disturb, 'pipeSegmentId': $segment_disturb, 'beginSignId': $begin_disturb}
    });
    // 干扰程度
    var $degree = $('#JQ_pipeline_degree').select3({
        search: false,
        data: [
            {id: 'BIG', text: '强'},
            {id: 'ORDINARY', text: '中'},
            {id: 'LITTLE', text: '弱'}
        ]
    });
    // 触发管道
    $pipeline_disturb.element.on('select', function (e, v) {
        var id = v || $pipeline_disturb.val();
        if (id) {
            // 管段
            DyyBase.ajax(DyyBase.url_segment(), {pipeLineId: id}, function (dataset) {
                var json = DyyBase.getSelect(dataset);
                $segment_disturb.add(json);
            });
            // 起点 & 终点
            DyyBase.ajax(DyyBase.url_pipe_pos(), {pipeLineId: id}, function (dataset) {
                var begin = DyyBase.getPos(dataset, 'begin');
                var end = DyyBase.getPos(dataset, 'end');
                $begin_disturb.asset(begin);
                $end_disturb.asset(end);
            });
        } else {
            $segment_disturb.add([]);
            $begin_disturb.add([]);
            $end_disturb.add([]);
        }
    });
    // 触发管段
    $segment_disturb.element.on('select', function (e, v) {
        var id = v || $segment_disturb.val();
        if (id) {
            // 起点 & 终点
            DyyBase.ajax(DyyBase.url_segment_pos(), {pipeSegmentId: id}, function (dataset) {
                var begin = DyyBase.getPos(dataset, 'begin');
                var end = DyyBase.getPos(dataset, 'end');
                $begin_disturb.asset(begin);
                $end_disturb.asset(end);
            });
        } else {
            $begin_disturb.add([]);
            $end_disturb.add([]);
        }
    });
    // 交直流干扰 - 列表
    var $table_disturb = $('#JQ_disturb_table');

    // 查询对象
    var filter_acdc = {
        // 交直流干扰 - 查询
        getDisFilter: function (param) {
            var data = {};
            data.mode = true;
            // 分页参数
            if (param) {
                if (param.start == 0) {
                    data['jsonBean.pageNum'] = 1;
                } else {
                    data['jsonBean.pageNum'] = param.start / 10 + 1;
                }
                data['jsonBean.pageCount'] = param.length;
            }
            data.pipeId = function () {
                var v = $pipeline_disturb.val();
                if (v) {
                    return v;
                }
                return '';
            }();
            data.pipeLineName = function () {
                var v = $pipeline_disturb.val('text');
                if (v) {
                    return v;
                }
                return '';
            }();
            data.beginMileage = function () {
                var v = $begin_disturb.val('mile');
                if (DyyBase.notEmpty(v)) {
                    return v;
                }
                return '';
            }();
            data.endMileage = function () {
                var v = $end_disturb.val('mile');
                if (DyyBase.notEmpty(v)) {
                    return v;
                }
                return '';
            }();
            data.disturbLevel = function () {
                var v = $degree.val();
                if (v) {
                    return v;
                }
                return '';
            }();
            return data;
        },
        // 交直流干扰 - 导出
        getDisExportFilter: function () {
            return filter.getDisFilter();
        }
    };

    // 加载表格
    var DTDIS;

    function loadDis() {
        DTDIS = $table_disturb.DataTable({
            'language': {
                'paginate': {
                    'next': '下一页',
                    'previous': '上一页'
                },
                'info': '本次检索共 _TOTAL_ 条，每页显示 10 条，共 _PAGES_ 页',
                'zeroRecords': DyyBase.table_empty(),
                'infoEmpty': ''
            },
            'autoWidth': false,
            'order': [],
            'serverSide': true,
            'pageLength': 10,
            'ordering': false,
            'processing': false,
            'searching': false,
            'lengthChange': false,
            'ajax': function (data, callback) {
                var param = filter_acdc.getDisFilter(data);
                DyyBase.ajax(corrctrlApi.url_dis_list(), param, function (dataset) {
                    var returnData = {};
                    returnData.draw = data.draw;
                    returnData.recordsTotal = dataset.result.total;
                    returnData.recordsFiltered = dataset.result.total;
                    returnData.data = DyyBase.clearNull(dataset.result.list);
                    callback(returnData);
                });
            },
            'drawCallback': function () {
                var th = $table_disturb.find('th');
                var empty = $table_disturb.find('td.dataTables_empty');
                empty.attr('colspan',th.length);
            },
            'columns': [
                {
                    data: 'pipeName', render: function (data, type, row) {
                    return '<span title="' + data + '">' + data + '</span><input type="hidden" name="gisId" value="' + row.gisId + '"><input type="hidden" name="pipeGisId" value="' + row.pipeGisId + '"><input type="hidden" name="identGisId" value="' + row.identGisId + '"><input type="hidden" name="valveRoomPoint" value="'+row.valRoomGisId+'">';
                }
                },
                {
                    data: 'fromName', render: function (data) {
                    return '<span title="' + data + '">' + data + '</span>';
                }
                },
                {
                    data: 'toName', render: function (data) {
                    return '<span title="' + data + '">' + data + '</span>';
                }
                },
                {
                    data: 'monitorNum', render: function (data) {
                    return '<span title="' + data + '">' + data + '</span>';
                }
                },
                {
                    data: 'mileage', render: function (data) {
                    return '<span title="' + data + '">' + data + '</span>';
                }
                },
                {
                    data: 'isType', render: function (data) {
                    return '<span title="' + data + '">' + data + '</span>';
                }
                },
                {
                    data: 'distrubLevel', render: function (data) {
                    return '<span title="' + data + '">' + data + '</span>';
                }
                }
            ]
        });
    }

    // 查询 - 交直流干扰
    $('#JQ_search_disturb').click(function () {
        if (DTDIS) {
            DTDIS.draw();
            filter_acdc.getDisExportFilter = filter_acdc.getDisFilter();
        }
    });

    // 导出 - 交直流干扰
    $('#JQ_export_disturb').click(function () {
        var $this = $(this);
        DyyBase.isLogin(function(){
            var param = filter_acdc.getDisFilter;
            if(param instanceof Function){
                param = param();
            }
            $this.EXPT({
                type: 'name',
                name: param.pipeLineName + '交直流干扰列表',
                param: param,
                server: DyyBase.root_path + '/corrctrl/acdcDisturb/exportAcdcExcel.json'
            });
        });
    });

    // 显示地图
    $('#JQ_toggle_map_span').click(function () {
        DyyBase.showMap('map', $table_disturb, 'JQ_dyMap', [{
            name: 'gisId',
            type: 'influceSourceId'
        }, {name: 'pipeGisId', type: 'pipeLineId'}, {name: 'identGisId', type: 'testPipeId'}, {name: 'valveRoomPoint', type: 'valveRoomPoint'}], true);
    });

    // 显示列表
    $('#JQ_toggle_list_span').click(function () {
        DyyBase.showMap('list', $table_disturb, 'JQ_dyMap', [{
            name: 'gisId',
            type: 'influceSourceId'
        }, {name: 'pipeGisId', type: 'pipeLineId'}, {name: 'identGisId', type: 'testPipeId'}, {name: 'valveRoomPoint', type: 'valveRoomPoint'}], true);
    });
    /*** 交直流干扰 - end ***/


    /*** 涂层 - start ***/
    // 管道
    var $pipeline_paint = $('#JQ_pipeline_paint').select3({
        data: $pipeline.val('store'),
        title: '管道'
    });

    // 管段
    var $segment_paint = $('#JQ_segment_paint').select3({
        title: '管段'
    });
    // 起点位置
    var $begin_paint = $('#JQ_begin_paint').select3({
        title: '起点位置',
        server: true,
        param: {'pipeLineId': $pipeline_paint, 'pipeSegmentId': $segment_paint}
    });
    // 终点位置
    var $end_paint = $('#JQ_end_paint').select3({
        title: '终点位置',
        server: true,
        param: {'pipeLineId': $pipeline_paint, 'pipeSegmentId': $segment_paint, 'beginSignId': $begin_paint}
    });
    // 触发管道
    $pipeline_paint.element.on('select', function (e, v) {
        var id = v || $pipeline_paint.val();
        if (id) {
            // 管段
            DyyBase.ajax(DyyBase.url_segment(), {pipeLineId: id}, function (dataset) {
                var json = DyyBase.getSelect(dataset);
                $segment_paint.add(json);
            });
            // 起点 & 终点
            DyyBase.ajax(DyyBase.url_pipe_pos(), {pipeLineId: id}, function (dataset) {
                var begin = DyyBase.getPos(dataset, 'begin');
                var end = DyyBase.getPos(dataset, 'end');
                $begin_paint.asset(begin);
                $end_paint.asset(end);
            });
        } else {
            $segment_paint.add([]);
            $begin_paint.add([]);
            $end_paint.add([]);
        }
    });
    // 触发管段
    $segment_paint.element.on('select', function (e, v) {
        var id = v || $segment_paint.val();
        if (id) {
            // 起点 & 终点
            DyyBase.ajax(DyyBase.url_segment_pos(), {pipeSegmentId: id}, function (dataset) {
                var begin = DyyBase.getPos(dataset, 'begin');
                var end = DyyBase.getPos(dataset, 'end');
                $begin_paint.asset(begin);
                $end_paint.asset(end);
            });
        } else {
            $begin_paint.add([]);
            $end_paint.add([]);
        }
    });

    // 默认选中
    $pipeline_paint.element.trigger('select');

    // 绘制 acvg 散点图
    function drawAcvg(data) {
        d3Charts.point({
            container: 'JQ_acvg_charts',
            color: ['#f0858f'],
            data: data,
            tip: {
                show: true,
                xtag: '里程/M',
                ytag: 'dB值'
            },
            xAxis: {
                ticks: Infinity
            },
            yAxis: {
                ticks: Infinity
            },
            layout: {
                xtag: '里程/M',
                ytag: 'dB值',
                margin: {
                    left: 40,
                    right: 20,
                    top: 30,
                    bottom: 40
                },
                xgrid: true,
                ygrid: true
            }
        });
    }

    // 绘制 dcvg 散点图
    function drawDcvg(data) {
        d3Charts.point({
            container: 'JQ_dcvg_charts',
            color: ['#f0858f'],
            data: data,
            xAxis: {
                ticks: Infinity
            },
            yAxis: {
                ticks: Infinity
            },
            tip: {
                show: true,
                xtag: '里程/M',
                ytag: 'IR%'
            },
            layout: {
                xtag: '里程/M',
                ytag: 'IR%',
                margin: {
                    left: 40,
                    right: 20,
                    top: 30,
                    bottom: 40
                },
                xgrid: true,
                ygrid: true
            }
        });
    }

    // 绘制 涂层等级分布
    function drawStep(data) {
        d3Charts.segment({
            container: 'JQ_paint_grade',
            color: ['#4a9ddf'],
            data: data,
            layout: {
                xtag: '里程/M',
                ytag: '涂层等级',
                margin: {
                    left: 40,
                    right: 20,
                    top: 30,
                    bottom: 40
                },
                xgrid: true,
                ygrid: true
            },
            xAxis: {
                ticks: Infinity
            },
            yAxis: {
                data: [0,4],
                ticks: 5
            },
            pointText: {
                circle: true
            },
            tip: {
                show: true,
                xtag: '里程/M',
                ytag: '涂层等级'
            }
        });
    }

    // 查询对象
    var filter_paint = {
        // 涂层
        getSearch: function () {
            var data = {};
            data.mode = true;
            data.pipeLineId = function () {
                var v = $pipeline_paint.val();
                if (v) {
                    return v;
                } else {
                    $pipeline_paint.element.TIP({content: '管道名称不能为空!'});
                    data.mode = false;
                }
                return '';
            }();
            data.pipeLineName = function () {
                var v = $pipeline_paint.val('text');
                if (v) {
                    return v;
                }
                return '';
            }();
            data.startMileage = function () {
                var v = $begin_paint.val('mile');
                if (DyyBase.notEmpty(v)) {
                    return v;
                }
                return '';
            }();
            data.endMileage = function () {
                var v = $end_paint.val('mile');
                if (DyyBase.notEmpty(v)) {
                    return v;
                }
                return '';
            }();
            return data;
        }
    };

    // 搜索
    $('#JQ_search_paint').click(function () {
        var param = filter_paint.getSearch();
        if (param.mode) {
            $('#JQ_export_paint').attr('data-empty','false');
            DyyBase.ajax(corrctrlApi.url_paint_rate(), param, function (dataset) {
                var avg = d3Charts.formart(dataset.result.acvgList, {x: 'mileage', y: 'svalue'});
                var empty = $('#JQ_acvg_charts').attr('data-empty');
                empty = '<img src="'+ empty +'">';
                if (avg.length > 0) {
                    drawAcvg(avg);
                }else{
                    $('#JQ_acvg_charts').html(empty);
                }

                var dvg = d3Charts.formart(dataset.result.dcvgList, {x: 'mileage', y: 'svalue'});
                if (dvg.length > 0) {
                    drawDcvg(dvg);
                }else{
                    $('#JQ_dcvg_charts').html(empty);
                }

                var step = d3Charts.formartX1X2Y(dataset.result.coatingGradeList);
                if (step.store.length > 0) {
                    drawStep(step);
                }else{
                    $('#JQ_paint_grade').html(empty);
                }
            });
        }else{
            $('#JQ_export_paint').attr('data-empty','true');
        }
    });

    // 导出pdf
    $('#JQ_export_paint').click(function(){
        var $this = $(this);
        DyyBase.isLogin(function(){
            var empty = $this.attr('data-empty');
            if(empty == 'true'){
                $this.MSG({
                    content: '尚未进行查询,将不能进行pdf导出!'
                });
            }else{
                var param = filter_paint.getSearch();
                if(param.pipeLineName){
                    $this.EXPT({
                        type: 'name',
                        name: param.pipeLineName + '涂层统计图',
                        yesBtnAct: function (callback, fname) {
                            callback();
                            canvasPdf.exportHtmlPdf({
                                dom: $('#JQ_paint_area'),
                                server: DyyBase.root_path + '/comm/downImgPdf.json',
                                param: {
                                    fileName: fname,
                                    name: param.pipeLineName + '涂层统计图'
                                }
                            });
                        }
                    });
                }
            }
        });
    });
    /*** 涂层 - end ***/


    // 记忆切换选项卡 - start
    var $tab_li = $('div.zy-cathodic-tab-head').find('li');
    var $tab_div = $('div.zy-cathodic-tab-div');
    function changeTab(tab){
        $tab_li.removeClass('active');
        $tab_div.addClass('hidden');

        $('#'+tab).removeClass('hidden');
        $('li[data-tab="'+tab+'"]').addClass('active');

        if(tab === 'JQ_acdc_div'){
            if (DTDIS) {
                DTDIS.draw();
            }else{
                loadDis();
            }
        }

        // 重绘charts box 大小
        DyyBase.setChartWidth();

        Dyy.setStorage('boardTab',tab);

        if($('#JQ_toggle_map_span').hasClass('active')){
            $('div.xyf-toggle-form-div').trigger('pick');
        }
    }

    $tab_li.click(function () {
        var $this = $(this);
        changeTab($this.attr('data-tab'));
    });

    var tab = Dyy.getStorage('boardTab');
    if(tab){
        changeTab(tab);
    }else{
        changeTab('JQ_rate_div');
    }
    // 记忆切换选项卡 - end

})(jQuery, window, document);
